<?php

namespace App\Models\Admin;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
    use HasFactory;
    protected $table = 'role';

    public $timestamps = false;
    //权限id ac 入库
    public function assignAuth($data){
        //判断是否存在auth_id
        if (isset($data['auth_id'])) {
           
        
        $post['auth_ids']=implode(',',$data['auth_id']);
                         	
        // var_dump($data['auth_id']);die;
    	$tmp = \App\Models\Admin\Auth::where('pid','!=','0') ->whereIn('id',$data['auth_id'])->get();
    	$ac = '';
    	foreach ($tmp as $key => $value) {
    		
    		$ac .= $value -> controller .'@'.$value ->action . ',';
    	}
    	$post['auth_ac'] = strtolower(rtrim($ac,','));
    	

    	return self::where('id',$data['id']) ->update($post);
       }else{

        return self::where('id',$data['id']) ->update(['auth_ids'=>'','auth_ac'=>'']);
       }

      
        
        // return self::where('id',$data['id']) ->update(['auth_ids'=>'','auth_ac'=>'']);


        


    }

  
}
